//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    formType: {},
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    time: {},
    winWidth: 0,
    winHeight: 0,
    // tab切换 
    currentTab: 0,
    ontips: true,
    tasks:[]
  },
  onLoad: function () {
    var _this = this;

    wx.getSystemInfo({

      success: function (res) {
        _this.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
    ////
    wx.request({
      url: '',
    })
  },
  //授权事件
  getUserInfo_zh: function (e) {
    var _this = this
    if (e.detail.userInfo) {

      app.setUserinfo();
      _this.setData({
        hasUserInfo: false
      })
    } else {
      wx.showToast({
        title: "为了您更好的体验,请先同意授权",
        icon: 'none',
        duration: 2000
      });
    }

  },
  //创建目标事件
  createGoal: function (e) {
    var _this = this;
    wx.getSetting({
      success: res => {
        if (!res.authSetting['scope.userInfo']) {
          _this.setData({
            hasUserInfo: true
          })
        }
      }
    })
  },

  //滑动模块
  bindChange: function (e) {

    var that = this;
    that.setData({ currentTab: e.detail.current });

  },
  swichNav: function (e) {
    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.request({
      url: `${app.globalData.apiurl}api/index/getEndTask`,
      method: 'GET',
      data: {
        uid: "I429402110844785"
      },
      success: res => {
        console.log(res)
        if (res.data.task.length == 0) {
          this.setData({
              ontips: false,
              tasks: res.data.task
          })
        }
      }
    })
  },
})
